package com.tianji.coupon.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tianji.coupon.pojo.Coupon;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 Mapper 接口
 * </p>
 *
 * @author 陈佳
 * @since 2024-08-29
 */
public interface CouponMapper extends BaseMapper<Coupon> {

    @Update("update coupon set issue_num = issue_num + 1 where id = #{couponId} and issue_num =  #{issueNum} and issue_num <= #{userLimit}")
    int incrIssueNum(@Param("couponId") Long couponId, @Param("issueNum") Integer issueNum, @Param("userLimit") Integer userLimit);


    List<Coupon> findExpiringCoupons(@Param("expiryTime")LocalDateTime expiryTime);
}
